package test;


import util.ColorDeformer;
import movement.StationaryObjectBounce;
import jgame.JGColor;
import jgame.JGObject;

public class House extends JGObject{

	/*private JGColor color = new JGColor(100,0,100,0);
	private int colorPercentage = 0;
	private static final int maxRadius = 16; */
	private int hitCount = 0;
	private static final int maxDamage = 200;
	private ColorDeformer colDef;
	private JGColor[][] curColor = new JGColor[0][0];
	
    public House (String name, boolean unique_id, double x, double y) {
        super (name, unique_id, x, y, Collision.BUILDING,"houseDmg0");
        colDef = new ColorDeformer(getBBox().width, getBBox().height, maxDamage);
    }

    
    public void hit(JGObject obj){
    	if (obj.colid == Collision.PROJECTILE){
    		
    		
    		// == ONE IMPL ===
    		// Set house damage:
        	// %7 just resets the sequence, 
    		//hitCount++;
    		//setImage("houseDmg" + hitCount/20 % 7);
    		
    		// == ANOTHER IMPL ==
    		colDef.hit(5);
    		curColor = colDef.getColors(); 
    	}
    	
    	if (obj.colid == Collision.PLAYER || obj.colid == Collision.ENEMY){
    		StationaryObjectBounce.getInstance().move(obj);
    	}
    	
    }
    
    public void paint(){
    	// below can be optimized TODO
    	for (int i = 0; i < curColor.length; i++){
    		for (int j = 0; j < curColor[i].length; j++){
    			if (curColor[i][j] != null){
    				eng.setColor(curColor[i][j]);
    				eng.drawRect(x+i, y+j, 6, 6, true, false);
    			}
    		}
    	}
    }
}
